home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / speech / lackey / lackey.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.8 KB  |  125 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*----------------------------------------------------------------
  18.  * 
  19.  *  lackey - speech recognition based application launcher
  20.  *  
  21.  *  08/93  John Magdziarz, Silicon Graphics, Inc.
  22.  * 
  23.  *----------------------------------------------------------------*/
  24.  
  25. #include    <stream.h>
  26. #include    <assert.h>
  27.  
  28. #include    <speech/Recognizer.h>
  29. #include    <speech/Word.h>
  30. #include    <speech/Database.h>
  31. #include    <speech/WordCallbackBindings.h>
  32. #include    <speech/Vocabulary.h>
  33. #include    <speech/Condition.h>
  34. #include    <speech/CharString.h>
  35.  
  36. class NameCommand
  37. {
  38.  public:
  39.    char *name;
  40.    char *command;
  41. };
  42.  
  43.  
  44. SpeechWord *appWord;
  45.  
  46.  
  47. long
  48. launchApp( const SpeechWord&, void* v )
  49.     { 
  50.           FILE *fid;
  51.  
  52.           cout << v << endl;
  53.           char *tmpStr = new(char[strlen((char *)v) + 2]);
  54.           char *cmd;
  55.       
  56.           strcpy(tmpStr, (char *)v);
  57.           strtok( (char *)tmpStr,  " ");
  58.           // check if app exists by trying to open it for read
  59.           if ((fid = fopen(tmpStr, "r")) == NULL) {
  60.             system("playaifc -p -q not_found.aifc &");
  61.             return 0;
  62.           }
  63.           fclose(fid);
  64.           strcpy(tmpStr, (char *)v);
  65.           strcat(tmpStr,"&");
  66.           if (system(tmpStr) != NULL)
  67.             cerr << "error executing system command\n" << flush;
  68.           return 1;
  69.         }
  70.  
  71.  
  72. int main( int argc, char* argv[] )
  73. {
  74.     char* applicationClass = "Lackey" ;
  75.     char* applicationName = argv[0] ;
  76.         const NameCommand apps[] = {
  77.           { "lackey", "/usr/sbin/playaifc -p -q serve.aifc"},
  78.           { "clock", "/usr/bin/X11/xclock"},
  79.           { "apanel", "/usr/sbin/apanel" },
  80.           { "shell", "/usr/sbin/xwsh" },
  81.           { (char *)0, (char *)0 },
  82.           };
  83.  
  84.     XrmDatabase xrmDatabase        // toolkit-dependent
  85.             = XrmGetFileDatabase( CharString( CharString(getenv( "HOME" ) ))
  86.                          + CharString("/.Xdefaults" )) ;
  87.  
  88.     SpeechRecognizer recognizer( applicationClass, applicationName, xrmDatabase,
  89.             "",     // default display, program name
  90.             SpeechRecognitionEventInterest     // get recognition events and all others
  91.                     | SpeechPoorMatchEventInterest
  92.                     | SpeechAmbiguousMatchEventInterest
  93.                     | SpeechErrorEventInterest ) ;
  94.     assert( recognizer.status( ) == SpeechOK ) ;
  95.  
  96.      int i = 0;
  97.         while (apps[i].name) {
  98.           appWord = new SpeechWord( (const char*)apps[i].name, 
  99.                     (const char*)apps[i].name, 
  100.                     recognizer, 
  101.                                     (const SpeechCallbackFunctionPointer) launchApp,
  102.                                     (void *)apps[i].command,
  103.                                     SpeechCondition( SpeechConditionGlobal ));
  104.           i++;
  105.           if( recognizer.status() != SpeechOK )
  106.              cerr << "trouble loading global words\n" << flush ;
  107.         }
  108.  
  109.         system("/usr/sbin/playaifc -p -q awaitcmd.aifc &");
  110.     // toolkit-dependent modification here
  111.     XEvent event ;
  112.     do
  113.         {
  114.         XNextEvent( recognizer.dpy(), &event ) ;
  115.         if( recognizer.isSpeechEvent( &event ) )
  116.             recognizer.processEvent( &event ) ;
  117.          else
  118.             ; // process as other/normal event
  119.         } while( event.type != DestroyNotify ) ;    // just to get rid of warning
  120.  
  121.     XrmDestroyDatabase( xrmDatabase ) ;
  122.  
  123.     return recognizer.status( ) ;
  124.     }
  125.